//
//  ITRuleLabel.m
//  Water
//
//  Created by seven on 2020/8/7.
//  Copyright © 2020 seven. All rights reserved.
//

#import "ITRuleLabel.h"

@implementation ITRuleLabel

- (void)initViews{
    [super initViews];
    self.backgroundColor = COLOR_WHITE;
}

- (void)setStrings:(NSArray *)strings{
    _strings = strings;
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect{
    [super drawRect:rect];
    if (_strings.count == 0) {
        return;
    }
    
    CGFloat topOffset = 0;
    
    UIColor *c = ColorWithHex(0xFAD015);
    UIFont *f = SemiboldFontWithSize(14);
    CGFloat space = 10;
    
    CGFloat w = self.width - 66;
    CGRect dr = CGRectMake(36, 0, self.width-66, 1000);

    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGRect pr = CGRectMake(20, 4, 9, 9);
    for (int i=0 ; i<_strings.count; i++) {
        NSString *str = _strings[i];
        //point
        CGContextAddEllipseInRect(context, pr);
        CGContextSetFillColorWithColor(context, c.CGColor);
        CGContextFillPath(context);
        
        NSMutableAttributedString *string = [NSAttributedString generateAttriuteStringWithStr:str WithColor:COLOR_333333 WithFont:f];
        string.lineSpacing = 4;
        dr.size.height = [string rectWithWidth:dr.size.width].size.height;
        [string drawInRect:dr];
        
        dr.origin.y += dr.size.height + space;
        pr.origin.y = dr.origin.y + 4;
    }
    
    self.contentHeight = dr.origin.y;
    
}

@end
